//
//  DepDocListController.m
//  HarmonizePub
//
//  Created by rzhy on 2016/11/18.
//  Copyright © 2016年 Zy. All rights reserved.
//

#import "DepDocListController.h"
#import "Config.h"
#import <UIScrollView+EmptyDataSet.h>
#import "DepDocListTableCell.h"
#import "DoctorIntroduceController.h"

static NSString * const CellIdentifier = @"Cell";

@interface DepDocListController () <UITableViewDelegate, UITableViewDataSource, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
{
    NSArray *_dataArray;
}
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation DepDocListController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self getDocList];
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    self.tableView.emptyDataSetSource = self;
    self.tableView.emptyDataSetDelegate = self;
    UINib *nib = [UINib nibWithNibName:[DepDocListTableCell registerName] bundle:nil];
    [self.tableView registerNib:nib forCellReuseIdentifier:CellIdentifier];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)getDocList {
    NSDictionary *cookie = @{CookieVaule : [UserDefaultsTool stringForKey:XHToken]};
    NSDictionary *param = @{@"ksdm" : self.dataDict[@"ksdm"]};
    [HTTPSTool POSTRequestWithPath:XHGetDocList cookie:cookie params:param success:^(NSDictionary * JSON) {
//        XHLog(@"科室医生-医生列表: %@", JSON)
        _dataArray = JSON[@"data"][@"list"];
        [_tableView reloadData];
    }];
}

#pragma mark - tableView delegate/dataSource Method
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [DepDocListTableCell cellHeight];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    DepDocListTableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    [cell setCellShowDataWithDataDictionary:_dataArray[indexPath.row]];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    NSDictionary *dataDict = _dataArray[indexPath.row];
    DoctorIntroduceController *doctorIntroduce = [[DoctorIntroduceController alloc] init];
    doctorIntroduce.selectIndex = 0;
    doctorIntroduce.ygdm = dataDict[@"ygdm"];
    [self.navigationController pushViewController:doctorIntroduce animated:YES];
}

#pragma mark - DZNEmptyDataSetSource Method
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
    UIImage *image = [UIImage imageNamed:@"LoadFailure.png"];
    return image;
}

- (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView {
    NSString *string = XHEmptyDes;
    NSAttributedString *abs = [[NSAttributedString alloc] initWithString:string attributes:nil];
    return abs;
}

- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
    return -64.0f;
}

#pragma mark - DZNEmptyDataSetDelegate Method
- (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView {
    return YES;
}

- (BOOL)emptyDataSetShouldAllowTouch:(UIScrollView *)scrollView {
    return YES;
}

- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView {
    return YES;
}

- (void)emptyDataSet:(UIScrollView *)scrollView didTapView:(UIView *)view {
    [self getDocList];
}

@end
